/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __DIM_ELF_H
#define __DIM_ELF_H

#include <linux/elf.h>

/**
 * dim_elf_get_ehdr - get and check elf header from elf file
 * @elf_file: elf file struct
 * @ehdr: elfhdr struct, the memory should be allocated by caller
 *
 * Return: 0 on success or -errno on failure
 */
int dim_elf_get_ehdr(struct file *elf_file, struct elfhdr *ehdr);

/**
 * dim_elf_get_phdrs - get all program headers from elf file, the memory of
 * phdrs should be free by caller using kfree()
 * @elf_file: elf file struct
 * @ehdr: elf header of file
 * @phdrs: pointer to program header array, the memory will be allocated in
 * this function
 * @num: number of program headers
 *
 * Return: 0 on success or -errno on failure
 */
int dim_elf_get_phdrs(struct file *elf_file,
		      struct elfhdr *ehdr,
		      struct elf_phdr **phdrs,
		      size_t *num);

/**
 * elf_get_section_by_name - search elf section by section name and return
 * section header
 * @elf_file: elf file struct
 * @ehdr: elf header of file
 * @name: name to search
 * @shdr: pointer to section header, the memory should be allocated by caller
 *
 * Return: 0 on success or -errno on failure
 */
int elf_get_section_by_name(struct file *elf_file,
			    struct elfhdr *ehdr,
			    const char *name,
			    struct elf_shdr *shdr);

#endif
